﻿<div class="content-wrapper">
    <section class="content-header">
        <h1>
            系统管理
            <small>数据字典</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">系统管理</a></li>
            <li class="active">数据字典</li>
        </ol>
    </section>
    <section class="content">
        <div class="row" style="padding-bottom:1px;">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">搜索条件</h3>
                        <div class="box-tools pull-right">
                            <button type="button" id="test" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip">
                                <i class="fa fa-minus"></i>
                            </button>
                        </div>
                    </div>
                    <div class="box-body">
                        <div class="input-group">
                            <span class="input-group-addon">日期范围</span>
                            <input type="text" ref="datemin" id="datemin" class="form-control" style="width:120px;">
                            <input type="text" ref="datemax" id="datemax" class="form-control" style="width:120px;margin-left:10px;">
                            @await Component.InvokeAsync("DictTypeS")
                        </div>
                        <div class="input-group" style="margin-top:5px;margin-left:-10px">
                            <button v-on:click="searchL" name="search" type="submit" class="btn btn-success" style="margin-left:10px;"><i class="fa fa-search"></i> 搜字典</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        <div id="toolbar" class="btn-group">
                            <button id="btn_add" v-on:click="showL" type="button" class="btn btn-default">
                                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                            </button>
                            <button id="btn_edit" v-on:click="editL" type="button" class="btn btn-default">
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
                            </button>
                            <button id="btn_delete" v-on:click="deleteL" type="button" class="btn btn-default">
                                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                            </button>
                        </div>
                        <table id="bootstraptable" class="table table-bordered text-nowrap table-hover"></table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
@section scripts{
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                datemin: '',
                datemax: '',
                DictType: ''
            },
            //beforeCreate: function () {
            //    this.$nextTick(function () {
            //        this.$refs.Dict.parentNode.parentNode.classList.add("active");
            //        this.$refs.Dict.classList.add("active");
            //    });
            //},
            mounted: function () {
                var _self = this;
                _self.$nextTick(function () {
                    //显示active
                    _self.$refs.Dict.parentNode.parentNode.classList.add("active");
                    _self.$refs.Dict.classList.add("active");

                    _self.$refs.datemin.value = _self.getCurrentMonthFirst();
                    _self.$refs.datemax.value = _self.getCurrentMonthLast();
                    //_self.datemin = _self.getCurrentMonthFirst();
                    //_self.datemax = _self.getCurrentMonthLast();
                    $('#datemin').datetimepicker({
                        format: 'yyyy-mm-dd',
                        minView: 2,
                        autoclose: true,
                        language: "zh-CN"
                    });
                    $('#datemax').datetimepicker({
                        format: 'yyyy-mm-dd',
                        minView: 2,
                        autoclose: true,
                        language: "zh-CN"
                    });
                    setTimeout(function () {
                        _self.loadL();
                        yui.getDomById("test").click();
                        $("div[class='pull-right search']")[0].children[0].setAttribute("placeholder", "字典名称");
                    }, 500);
                });
            },
            methods: {
                loadL: function () {
                    _self = this;
                    var obj = [{
                        checkbox: true,             //是否显示复选框
                        visible: true
                    },
                    {
                        field: 'DictId',
                        title: 'Id',
                        visible: false
                    }, {
                        field: 'DictName',
                        title: '字典名称',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'DictType',
                        title: '字典类型',
                        align: 'center',
                        sortable: true,
                        formatter: function (value, row, index) {
                            switch (value) {
                                case "1":
                                    return "单位类别";
                                case "2":
                                    return "物料分类";
                                case "3":
                                    return "入库单";
                                case "4":
                                    return "出库单";
                                case "5":
                                    return "设备类型";
                                case "6":
                                    return "设备产权";
                                default:
                                    return "-";
                            }
                        }
                    }, {
                        field: 'Remark',
                        align: 'center',
                        title: '备注'
                    }, {
                        field: 'CName',
                        title: '创建人',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'CreateDate',
                        align: 'center',
                        title: '创建时间',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return _self.jsonDateFormat(value);
                        }
                    }, {
                        field: 'UName',
                        align: 'center',
                        title: '修改人',
                        sortable: true
                    }, {
                        field: 'ModifiedDate',
                        title: '修改时间',
                        align: 'center',
                        sortable: true,
                        formatter: function (value, row, index) {
                            return _self.jsonDateFormat(value);
                        }
                    }];
                    var qParams = {
                        DictType: _self.DictType
                    };
                    yui.table("bootstraptable", "/Dict/List", obj, "POST", "DictId", true, qParams);
                },
                showL: function () {
                    yui.layershow("添加字典", "/Dict/Add", 510, 400);
                },
                searchL: function () {
                    var qParams = {
                        DictType: _self.DictType,
                    };
                    var query = {
                        silent: true,
                        query: qParams
                    };
                    $("#bootstraptable").bootstrapTable('refresh', query);
                },
                editL: function () {
                    var arr = $("#bootstraptable").bootstrapTable('getSelections');
                    if (arr.length > 0) {
                        var index = layer.confirm("您确定要修改吗？", { btn: ["确定", "取消"] }, function () {
                            layer.close(index);
                            var id = arr[0].DictId;
                            yui.layershow("修改字典", "/Dict/Add?id=" + id, 510, 400);
                        }, function () {

                        });
                    } else {
                        layer.alert("请选中行", { icoon: 3, skin: "layer-ext-moon" });
                    }
                },
                deleteL: function () {
                    var _self = this;
                    var arr = $("#bootstraptable").bootstrapTable('getSelections');
                    if (arr.length > 0) {
                        var index = layer.confirm("您确定要删除吗？", { btn: ["确定", "取消"] }, function () {
                            var id = arr[0].DictId;
                            yui.$axiosget('/Dict/Delete?id=' + id)
                                .then(function (response) {
                                    if (response.data.Item1) {
                                        layer.msg(response.data.Item2 || errorMsg, { icon: 1 });
                                        _self.searchL();
                                    } else {
                                        layer.msg(response.data.Item2 || errorMsg, { icon: 5 });
                                    }
                                })
                                .catch(function (error) {
                                    layer.msg(error.message, { icon: 5 });
                                });
                            layer.close(index);
                        });
                    } else {
                        layer.alert("请选中行", { icoon: 3, skin: "layer-ext-moon" });
                    }
                }
            }
        });
    </script>
}